home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / src / GLperf3.12-src.lha / GLperf / TransMap.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-01  |  17.4 KB  |  418 lines

  1. /*
  2.  * (c) Copyright 1995, Silicon Graphics, Inc.
  3.  * ALL RIGHTS RESERVED
  4.  * Permission to use, copy, modify, and distribute this software for
  5.  * any purpose and without fee is hereby granted, provided that the above
  6.  * copyright notice appear in all copies and that both the copyright notice
  7.  * and this permission notice appear in supporting documentation, and that
  8.  * the name of Silicon Graphics, Inc. not be used in advertising
  9.  * or publicity pertaining to distribution of the software without specific,
  10.  * written prior permission.
  11.  *
  12.  * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
  13.  * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
  14.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
  15.  * FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL SILICON
  16.  * GRAPHICS, INC.  BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
  17.  * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
  18.  * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
  19.  * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
  20.  * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC.  HAS BEEN
  21.  * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
  22.  * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
  23.  * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
  24.  *
  25.  * US Government Users Restricted Rights
  26.  * Use, duplication, or disclosure by the Government is subject to
  27.  * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
  28.  * (c)(1)(ii) of the Rights in Technical Data and Computer Software
  29.  * clause at DFARS 252.227-7013 and/or in similar or successor
  30.  * clauses in the FAR or the DOD or NASA FAR Supplement.
  31.  * Unpublished-- rights reserved under the copyright laws of the
  32.  * United States.  Contractor/manufacturer is Silicon Graphics,
  33.  * Inc., 2011 N.  Shoreline Blvd., Mountain View, CA 94039-7311.
  34.  *
  35.  * Author: John Spitzer, SGI Applied Engineering
  36.  *
  37.  */
  38. #include <math.h>
  39. #include <malloc.h>
  40. #include "Image.h"
  41. #include "TransMap.h"
  42.  
  43. const int numMaps = 10;
  44. const int numScales = 5;
  45.  
  46. void new_TransferMap(TransferMapPtr this)
  47. {
  48.     this->maps = 0;
  49. }
  50.  
  51. void delete_TransferMap(TransferMapPtr this)
  52. {
  53.     int i;
  54.  
  55.     if (this->maps) {
  56.     for (i = 0; i < numMaps; i++)
  57.         if (this->maps[i]) free(this->maps[i]);
  58.     free(this->maps);
  59.     }
  60. }
  61.  
  62. /*
  63.  * NOTE:
  64.  * This procedure should probably be augmented in the future to set all state
  65.  * back to default which alters DrawPixels operation.  This is because the
  66.  * convolution definition process and the color table definition process both
  67.  * follow the pixel operations that apply to DrawPixels.
  68.  */
  69. void SaveAndSetPixelStore(GLint* alignment, GLint* lsbfirst, GLint* rowlength, GLint* skippixels, GLint* skiprows, GLint* swapbytes)
  70. {
  71.     /* save PixelStore mode */
  72.     glGetIntegerv(GL_UNPACK_ALIGNMENT, alignment);
  73.     glGetIntegerv(GL_UNPACK_LSB_FIRST, lsbfirst);
  74.     glGetIntegerv(GL_UNPACK_ROW_LENGTH, rowlength);
  75.     glGetIntegerv(GL_UNPACK_SKIP_PIXELS, skippixels);
  76.     glGetIntegerv(GL_UNPACK_SKIP_ROWS, skiprows);
  77.     glGetIntegerv(GL_UNPACK_SWAP_BYTES, swapbytes);
  78.     glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
  79.     glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE);
  80.     glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
  81.     glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
  82.     glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
  83.     glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE);
  84. }
  85.  
  86. /*
  87.  * NOTE:
  88.  * This procedure should be similarly augmented like SaveAndSetPixelStore to pop
  89.  * the pixel operations state that applies to DrawPixels.
  90.  */
  91. void RestorePixelStore(GLint alignment, GLint lsbfirst, GLint rowlength, GLint skippixels, GLint skiprows, GLint swapbytes)
  92. {
  93.     glPixelStorei(GL_UNPACK_ALIGNMENT, alignment);
  94.     glPixelStorei(GL_UNPACK_LSB_FIRST, lsbfirst);
  95.     glPixelStorei(GL_UNPACK_ROW_LENGTH, rowlength);
  96.     glPixelStorei(GL_UNPACK_SKIP_PIXELS, skippixels);
  97.     glPixelStorei(GL_UNPACK_SKIP_ROWS, skiprows);
  98.     glPixelStorei(GL_UNPACK_SWAP_BYTES, swapbytes);
  99. }
  100.  
  101. int TransferMap__SetState(TransferMapPtr this)
  102. {
  103.     GLint maxSize;
  104.     GLfloat *ptr;
  105.     int *mapSizes;
  106.     int i, j, k;
  107.  
  108.     /* Set scales and biases */
  109.     glPixelTransferi(GL_INDEX_SHIFT, this->indexShift);
  110.     glPixelTransferi(GL_INDEX_OFFSET, this->indexOffset);
  111.     glPixelTransferf(GL_RED_SCALE, this->redScale);
  112.     glPixelTransferf(GL_RED_BIAS, this->redBias);
  113.     glPixelTransferf(GL_GREEN_SCALE, this->greenScale);
  114.     glPixelTransferf(GL_GREEN_BIAS, this->greenBias);
  115.     glPixelTransferf(GL_BLUE_SCALE, this->blueScale);
  116.     glPixelTransferf(GL_BLUE_BIAS, this->blueBias);
  117.     glPixelTransferf(GL_ALPHA_SCALE, this->alphaScale);
  118.     glPixelTransferf(GL_ALPHA_BIAS, this->alphaBias);
  119.     glPixelTransferf(GL_DEPTH_SCALE, this->depthScale);
  120.     glPixelTransferf(GL_DEPTH_BIAS, this->depthBias);
  121.  
  122.     /* Our maps are enumerated in the TransferMap structure in the
  123.      * same order as they're defined in gl.h.  This makes handling
  124.      * the maps much easier.
  125.      */
  126.  
  127.  
  128.    mapSizes = (int*)&this->itoiMapSize;
  129.  
  130.     /* Check if our table sizes are within limits and powers of 2 */
  131.     glGetIntegerv(GL_MAX_PIXEL_MAP_TABLE, &maxSize);
  132.     for (i = 0; i < numMaps; i++)
  133.       if (mapSizes[i] > maxSize ||
  134.             mapSizes[i] & mapSizes[i] - 1)
  135.             return -1;
  136.  
  137.     /* Define our pixel maps */
  138.     this->maps = (GLfloat**)malloc(sizeof(GLfloat*) * numMaps);
  139.     CheckMalloc(this->maps);
  140.     for (i = 0; i < numMaps; i++) {
  141.         /* Create table and fill in some inverse values */
  142.  
  143.     this->maps[i] = (GLfloat*)malloc(sizeof(GLfloat) * mapSizes[i]);
  144.         CheckMalloc(this->maps[i]);
  145.         ptr = this->maps[i];
  146.     if (mapSizes[i] == 1) {
  147.         *ptr++ = (GLfloat)1.;
  148.     } else {
  149.             for (j = 0; j < mapSizes[i]; j++)
  150.                 *ptr++ = (GLfloat)(1. - (GLfloat)j/(GLfloat)(mapSizes[i]-1));
  151.     }
  152.         /* Define it to OpenGL */
  153.         glPixelMapfv(GL_PIXEL_MAP_I_TO_I + i, mapSizes[i], this->maps[i]);
  154.     }
  155.  
  156.     glPixelTransferi(GL_MAP_COLOR, this->mapColor);
  157.     glPixelTransferi(GL_MAP_STENCIL, this->mapStencil);
  158.  
  159. #ifdef GL_EXT_convolution
  160.     {
  161.         GLint maxConvWidth, maxConvHeight;
  162.         GLfloat *convFilter, *convElm;
  163.         GLfloat *convRowFilter, *convRowElm, *convColumnFilter, *convColumnElm;
  164.         GLint alignment, lsbfirst, rowlength, skippixels, skiprows, swapbytes;
  165.         GLint convSize;
  166.     GLfloat sums[4];
  167.     GLfloat scales[4];
  168.     GLfloat defaultscales[4] = {1., 1., 1., 1.};
  169.  
  170.     /* First see if convolution extension is supported */
  171. /*
  172.     if (!strstr(glGetString(GL_EXTENSIONS), "GL_EXT_convolution")) return -1;
  173. */
  174.  
  175.         glDisable(GL_CONVOLUTION_1D_EXT);
  176.         glDisable(GL_CONVOLUTION_2D_EXT);
  177.         glDisable(GL_SEPARABLE_2D_EXT);
  178.  
  179.     mysrand(15000);
  180.  
  181.         switch (this->convTarget) {
  182.         case GL_CONVOLUTION_1D_EXT:
  183.             glGetConvolutionParameterivEXT(this->convTarget, GL_MAX_CONVOLUTION_WIDTH_EXT, &maxConvWidth);
  184.             if (this->convWidth > maxConvWidth) return -1;
  185.         for (i=0; i<4; i++)
  186.         sums[i] = 0.;
  187.         convFilter = (GLfloat*)malloc(this->convWidth * 4 * sizeof(GLfloat));
  188.         convElm = convFilter;
  189.         for (i = 0; i < this->convWidth; i++) {
  190.         for (k = 0; k < 4; k++) {
  191.             *convElm = (double)myrand()/(double)MY_RAND_MAX;
  192.             sums[k] += *convElm;
  193.             convElm++;
  194.         }
  195.         }
  196.             SaveAndSetPixelStore(&alignment, &lsbfirst, &rowlength, &skippixels, &skiprows, &swapbytes);
  197.         for (i=0; i<4; i++)
  198.         scales[i] = 1./sums[i];
  199.         glConvolutionParameterfvEXT(GL_CONVOLUTION_1D_EXT, GL_CONVOLUTION_FILTER_SCALE_EXT, scales);
  200.             glConvolutionFilter1DEXT(this->convTarget, this->convInternalFormat,
  201.                 this->convWidth,
  202.                 GL_RGBA, GL_FLOAT, convFilter);
  203.         glConvolutionParameterfvEXT(GL_CONVOLUTION_1D_EXT, GL_CONVOLUTION_FILTER_SCALE_EXT, defaultscales);
  204.             RestorePixelStore(alignment, lsbfirst, rowlength, skippixels, skiprows, swapbytes);
  205.             free(convFilter);
  206.             glConvolutionParameteriEXT(this->convTarget, GL_CONVOLUTION_BORDER_MODE_EXT, GL_REDUCE_EXT);
  207.             glEnable(GL_CONVOLUTION_1D_EXT);
  208.             break;
  209.         case GL_CONVOLUTION_2D_EXT:
  210.             /* Query Size and make sure we're in bounds */
  211.             glGetConvolutionParameterivEXT(this->convTarget, GL_MAX_CONVOLUTION_WIDTH_EXT, &maxConvWidth);
  212.             glGetConvolutionParameterivEXT(this->convTarget, GL_MAX_CONVOLUTION_HEIGHT_EXT, &maxConvHeight);
  213.             if (this->convWidth > maxConvWidth) return -1;
  214.             if (this->convHeight > maxConvHeight) return -1;
  215.         for (i=0; i<4; i++)
  216.         sums[i] = 0.;
  217.         convFilter = (GLfloat*)malloc(this->convHeight * this->convWidth * 4 * sizeof(GLfloat));
  218.         convElm = convFilter;
  219.         for (j = 0; j < this->convHeight; j++) {
  220.         for (i = 0; i < this->convWidth; i++) {
  221.             for (k = 0; k < 4; k++) {
  222.             *convElm = (double)myrand()/(double)MY_RAND_MAX;
  223.             sums[k] += *convElm;
  224.             convElm++;
  225.             }
  226.         }
  227.         }
  228.             SaveAndSetPixelStore(&alignment, &lsbfirst, &rowlength, &skippixels, &skiprows, &swapbytes);
  229.         for (i=0; i<4; i++)
  230.         scales[i] = 1./sums[i];
  231.         glConvolutionParameterfvEXT(this->convTarget, GL_CONVOLUTION_FILTER_SCALE_EXT, scales);
  232.             glConvolutionFilter2DEXT(this->convTarget, this->convInternalFormat,
  233.                 this->convWidth, this->convHeight,
  234.                 GL_RGBA, GL_FLOAT, convFilter);
  235.         glConvolutionParameterfvEXT(this->convTarget, GL_CONVOLUTION_FILTER_SCALE_EXT, defaultscales);
  236.             RestorePixelStore(alignment, lsbfirst, rowlength, skippixels, skiprows, swapbytes);
  237.             free(convFilter);
  238.             glConvolutionParameteriEXT(this->convTarget, GL_CONVOLUTION_BORDER_MODE_EXT, GL_REDUCE_EXT);
  239.             glEnable(GL_CONVOLUTION_2D_EXT);
  240.             break;
  241.         case GL_SEPARABLE_2D_EXT:
  242.             glGetConvolutionParameterivEXT(this->convTarget, GL_MAX_CONVOLUTION_WIDTH_EXT, &maxConvWidth);
  243.             glGetConvolutionParameterivEXT(this->convTarget, GL_MAX_CONVOLUTION_HEIGHT_EXT, &maxConvHeight);
  244.             if (this->convWidth > maxConvWidth) return -1;
  245.             if (this->convHeight > maxConvHeight) return -1;
  246.             for (i=0; i<4; i++)
  247.                 sums[i] = 0.;
  248.         convRowElm = convRowFilter = (GLfloat*)malloc(this->convWidth * 4 * sizeof(GLfloat));
  249.         convColumnElm = convColumnFilter = (GLfloat*)malloc(this->convHeight * 4 * sizeof(GLfloat));
  250.             for (i = 0; i < this->convWidth; i++)
  251.                 for (k = 0; k < 4; k++)
  252.                     *convRowElm++ = (double)myrand()/(double)MY_RAND_MAX;
  253.             for (i = 0; i < this->convHeight; i++)
  254.                 for (k = 0; k < 4; k++)
  255.                     *convColumnElm++ = (double)myrand()/(double)MY_RAND_MAX;
  256.         for (j = 0; j < this->convHeight; j++)
  257.         for (i = 0; i < this->convWidth; i++)
  258.             for (k = 0; k < 4; k++)
  259.             sums[k] += convRowFilter[4 * i + k] * convColumnFilter[4 * j + k];
  260.             SaveAndSetPixelStore(&alignment, &lsbfirst, &rowlength, &skippixels, &skiprows, &swapbytes);
  261.         for (i=0; i<4; i++)
  262.         scales[i] = 1./sqrt(sums[i]);
  263.         glConvolutionParameterfvEXT(this->convTarget, GL_CONVOLUTION_FILTER_SCALE_EXT, scales);
  264.             glSeparableFilter2DEXT(this->convTarget, this->convInternalFormat,
  265.                 this->convWidth, this->convHeight,
  266.                 GL_RGBA, GL_FLOAT,
  267.                 convRowFilter, convColumnFilter);
  268.         glConvolutionParameterfvEXT(this->convTarget, GL_CONVOLUTION_FILTER_SCALE_EXT, defaultscales);
  269.             RestorePixelStore(alignment, lsbfirst, rowlength, skippixels, skiprows, swapbytes);
  270.             free(convRowFilter);
  271.             free(convColumnFilter);
  272.             glConvolutionParameteriEXT(this->convTarget, GL_CONVOLUTION_BORDER_MODE_EXT, GL_REDUCE_EXT);
  273.             glEnable(GL_SEPARABLE_2D_EXT);
  274.             break;
  275.     default:
  276.         break;
  277.         }
  278.     }
  279.  
  280.     glPixelTransferf(GL_POST_CONVOLUTION_RED_SCALE_EXT, this->convRedScale);
  281.     glPixelTransferf(GL_POST_CONVOLUTION_RED_BIAS_EXT, this->convRedBias);
  282.     glPixelTransferf(GL_POST_CONVOLUTION_GREEN_SCALE_EXT, this->convGreenScale);
  283.     glPixelTransferf(GL_POST_CONVOLUTION_GREEN_BIAS_EXT, this->convGreenBias);
  284.     glPixelTransferf(GL_POST_CONVOLUTION_BLUE_SCALE_EXT, this->convBlueScale);
  285.     glPixelTransferf(GL_POST_CONVOLUTION_BLUE_BIAS_EXT, this->convBlueBias);
  286.     glPixelTransferf(GL_POST_CONVOLUTION_ALPHA_SCALE_EXT, this->convAlphaScale);
  287.     glPixelTransferf(GL_POST_CONVOLUTION_ALPHA_BIAS_EXT, this->convAlphaBias);
  288. #endif
  289.  
  290. #ifdef GL_SGI_color_matrix
  291.     {
  292.         GLfloat *mtrx = &this->cmatrixR0;
  293.  
  294.         glMatrixMode(GL_COLOR);
  295.         if (mtrx[0 ] == 1. && mtrx[1 ] == 0. && mtrx[2 ] == 0. && mtrx[3 ] == 0. &&
  296.             mtrx[4 ] == 0. && mtrx[5 ] == 1. && mtrx[6 ] == 0. && mtrx[7 ] == 0. &&
  297.             mtrx[8 ] == 0. && mtrx[9 ] == 0. && mtrx[10] == 1. && mtrx[11] == 0. &&
  298.             mtrx[12] == 0. && mtrx[13] == 0. && mtrx[14] == 0. && mtrx[15] == 1.) {
  299.             /* If matrix is the identity, then don't call glLoadMatrix */
  300.             glLoadIdentity();
  301.         } else {
  302.             glLoadMatrixf(mtrx);
  303.         }
  304.         glMatrixMode(GL_MODELVIEW);
  305.  
  306.         glPixelTransferf(GL_POST_COLOR_MATRIX_RED_SCALE_SGI, this->cmatrixRedScale);
  307.         glPixelTransferf(GL_POST_COLOR_MATRIX_RED_BIAS_SGI, this->cmatrixRedBias);
  308.         glPixelTransferf(GL_POST_COLOR_MATRIX_GREEN_SCALE_SGI, this->cmatrixGreenScale);
  309.         glPixelTransferf(GL_POST_COLOR_MATRIX_GREEN_BIAS_SGI, this->cmatrixGreenBias);
  310.         glPixelTransferf(GL_POST_COLOR_MATRIX_BLUE_SCALE_SGI, this->cmatrixBlueScale);
  311.         glPixelTransferf(GL_POST_COLOR_MATRIX_BLUE_BIAS_SGI, this->cmatrixBlueBias);
  312.         glPixelTransferf(GL_POST_COLOR_MATRIX_ALPHA_SCALE_SGI, this->cmatrixAlphaScale);
  313.         glPixelTransferf(GL_POST_COLOR_MATRIX_ALPHA_BIAS_SGI, this->cmatrixAlphaBias);
  314.     }
  315. #endif
  316.  
  317. #ifdef GL_SGI_color_table
  318.     if (this->colorTable) {
  319.     void *colorTable;
  320.     GLint colorTableSize;
  321.         GLint alignment, lsbfirst, rowlength, skippixels, skiprows, swapbytes;
  322.  
  323.     /* First see if color table extension is supported */
  324.     if (!strstr(glGetString(GL_EXTENSIONS), "GL_SGI_color_table")) return -1;
  325.  
  326.     /* Then verify that its width is a power of 2 */
  327.     if (this->colorTableWidth & this->colorTableWidth - 1) return -1;
  328.  
  329.     colorTable = new_ImageData(this->colorTableWidth, 1,
  330.                 GL_RGBA, GL_UNSIGNED_BYTE,
  331.                 4, False, False, 0, &colorTableSize);
  332.         SaveAndSetPixelStore(&alignment, &lsbfirst, &rowlength, &skippixels, &skiprows, &swapbytes);
  333.     glColorTableSGI(GL_COLOR_TABLE_SGI, this->colorTableInternalFormat, this->colorTableWidth,
  334.             GL_RGBA, GL_UNSIGNED_BYTE, colorTable);
  335.         RestorePixelStore(alignment, lsbfirst, rowlength, skippixels, skiprows, swapbytes);
  336.     AlignFree(colorTable);
  337.     glEnable(GL_COLOR_TABLE_SGI);
  338.     } else {
  339.     glDisable(GL_COLOR_TABLE_SGI);
  340.     }
  341.  
  342.     if (this->pcColorTable) {
  343.     void *pcColorTable;
  344.     GLint pcColorTableSize;
  345.         GLint alignment, lsbfirst, rowlength, skippixels, skiprows, swapbytes;
  346.  
  347.     /* First see if color table extension is supported */
  348.     if (!strstr(glGetString(GL_EXTENSIONS), "GL_SGI_color_table")) return -1;
  349.  
  350.     /* Then verify that its width is a power of 2 */
  351.     if (this->pcColorTableWidth & this->pcColorTableWidth - 1) return -1;
  352.  
  353.     pcColorTable = new_ImageData(this->pcColorTableWidth, 1,
  354.                 GL_RGBA, GL_UNSIGNED_BYTE,
  355.                 4, False, False, 0, &pcColorTableSize);
  356.         SaveAndSetPixelStore(&alignment, &lsbfirst, &rowlength, &skippixels, &skiprows, &swapbytes);
  357.     glColorTableSGI(GL_COLOR_TABLE_SGI, this->pcColorTableInternalFormat, this->pcColorTableWidth,
  358.             GL_RGBA, GL_UNSIGNED_BYTE, pcColorTable);
  359.         RestorePixelStore(alignment, lsbfirst, rowlength, skippixels, skiprows, swapbytes);
  360.     AlignFree(pcColorTable);
  361.     glEnable(GL_POST_CONVOLUTION_COLOR_TABLE_SGI);
  362.     } else {
  363.     glDisable(GL_POST_CONVOLUTION_COLOR_TABLE_SGI);
  364.     }
  365.  
  366.     if (this->pcmColorTable) {
  367.     void *pcmColorTable;
  368.     GLint pcmColorTableSize;
  369.         GLint alignment, lsbfirst, rowlength, skippixels, skiprows, swapbytes;
  370.  
  371.     /* First see if color table extension is supported */
  372.     if (!strstr(glGetString(GL_EXTENSIONS), "GL_SGI_color_table")) return -1;
  373.  
  374.     /* Then verify that its width is a power of 2 */
  375.     if (this->pcmColorTableWidth & this->pcmColorTableWidth - 1) return -1;
  376.  
  377.     pcmColorTable = new_ImageData(this->pcmColorTableWidth, 1,
  378.                 GL_RGBA, GL_UNSIGNED_BYTE,
  379.                 4, False, False, 0, &pcmColorTableSize);
  380.         SaveAndSetPixelStore(&alignment, &lsbfirst, &rowlength, &skippixels, &skiprows, &swapbytes);
  381.     glColorTableSGI(GL_COLOR_TABLE_SGI, this->pcmColorTableInternalFormat, this->pcmColorTableWidth,
  382.             GL_RGBA, GL_UNSIGNED_BYTE, pcmColorTable);
  383.         RestorePixelStore(alignment, lsbfirst, rowlength, skippixels, skiprows, swapbytes);
  384.     AlignFree(pcmColorTable);
  385.     glEnable(GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI);
  386.     } else {
  387.     glDisable(GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI);
  388.     }
  389. #endif
  390.  
  391. #ifdef GL_EXT_histogram
  392.     if (this->histogram) {
  393.         /* First see if histogram extension is supported */
  394.         if (!strstr(glGetString(GL_EXTENSIONS), "GL_EXT_histogram")) return -1;
  395.  
  396.     /* Then verify that its table width is a power of 2 */
  397.     if (this->histogramWidth & this->histogramWidth - 1) return -1;
  398.  
  399.     glHistogramEXT(GL_HISTOGRAM_EXT, this->histogramWidth, 
  400.                        this->histogramInternalFormat, this->histogramSink);
  401.     glEnable(GL_HISTOGRAM_EXT);
  402.     } else {
  403.     glDisable(GL_HISTOGRAM_EXT);
  404.     }
  405.  
  406.     if (this->minmax) {
  407.         /* First see if histogram extension is supported */
  408.         if (!strstr(glGetString(GL_EXTENSIONS), "GL_EXT_histogram")) return -1;
  409.  
  410.     glMinmaxEXT(GL_MINMAX_EXT, this->minmaxInternalFormat, this->minmaxSink);
  411.     glEnable(GL_MINMAX_EXT);
  412.     } else {
  413.     glDisable(GL_MINMAX_EXT);
  414.     }
  415. #endif
  416.     return 0;
  417. }
  418.